<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/common.css">
</head>
<body>
<div class="col-xs-12 col-sm-12  col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<div class="form-group topCheckDiv hide">
				<div style="float:left;">
					<button class="btn btn-primary" id="goReturn" onclick="location.href='javascript:history.go(-1)'">返回</button>
				</div>
				<div style="float:right;padding-right:20px;">
					<button class="btn btn-primary hide" id="verifyOk">通过</button>
					<button class="btn btn-primary hide" id="verifyNo">驳回</button>
					<button class="btn btn-primary" id="verifyDesign">审批流程</button>
					<button class="btn btn-primary" id="verifyLogo">审批记录</button>
				</div>
			</div>
			<input type="hidden" id="customerId" name="customerId">
			<div class='form-group'>
				<label class='col-md-2 control-label'>客户名称</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='companyName' id='companyName' data-bv-notempty='true' data-bv-notempty-message='客户名称 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>所属行业id</label>
				<div class='col-md-10'>
					
					<select name="industryParaId" id="industryParaId" data-bv-notempty='true' data-bv-notempty-message='所属行业id 不能为空'>
						
					</select>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>注册地</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='registerPlace' id='registerPlace'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>客户地址</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='companyAddr' id='companyAddr' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>法定代表人</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='legalRepresentative' id='legalRepresentative' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>注册资本</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='registeredCapital' id='registeredCapital' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>营业期限开始</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='businessTermBegin' id='businessTermBegin'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>营业期限结束</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='businessTermEnd' id='businessTermEnd' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>统一社会信用代码</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='creditCode' id='creditCode' data-bv-notempty='true' data-bv-notempty-message='统一社会信用代码 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>商务联系人</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='businessUser' id='businessUser' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>商务联系人电话</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='businessUserTel' id='businessUserTel' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>归属业务员</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='followUserId' id='followUserId' onclick="openIframeUserList(this)" readonly="readonly" placeholder='点击选择'>
				</div>
			</div>


			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
					    <button class="btn btn-primary" onclick="location.href='javascript:history.go(-1)'">返回</button>
						<button class="btn btn-primary" type="submit" onclick="update()">
							<i class="fa fa-save"></i> 保存并提交审核
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>
	<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript">
		var type = GetQueryString("type");//等于1位审核模式、等于0位审核结果详情查看
		var dataStatus = GetQueryString("dataStatus");//等于2为审核中状态
		if(type == null){
			$(".topCheckDiv").addClass("hide");
		}
		if(type == 1){
			$(".topCheckDiv").removeClass("hide");
			if(dataStatus == 2){
				$(".topCheckDiv div .hide").removeClass("hide");
			}
			$(".form-group input,.form-group select").attr("disabled","disabled");
			$(".form-actions").addClass("hide");
		}
		if(type == 0){
			$(".topCheckDiv").removeClass("hide");
			$(".form-actions,#goReturn").addClass("hide");
		}
		layui.use(['layer','laydate'], function(){
		    var layer = layui.layer;
		});
		$(function(){
			var readId = GetQueryString("readId");
			$("#verifyDesign").click(function(){
				showMaxWindow(urlRootPrefix + "/pages/flowDesign/hccflow/page/design.html?flowId="+readId+"&status=2","审批流程走势图");
			});
			$("#verifyLogo").click(function(){
				showMaxWindow(urlRootPrefix + "/pages/common/verifyLogList.html?readId="+readId,"审批记录");
			});
			//VerifyType只能传入3(通过)/4(驳回)/6(转办)
			$("#verifyOk").click(function(){
				layer.open({
		            type: 1,
		            title:'请确认是否通过该审核?',
		            area : [ '472px', '279px' ], //弹出层宽高
		            content: "<div style='margin-left:10px'>审核说明：</div><div style='display:flex;justify-content:center;'><textarea id='area' style='width:95%;height:150px;'></textarea></div>",
		            btn:['保存','取消'],
		            yes:function (index,layero) {
		                 //获取输入框里面的值
		                var closeContent = top.$("#area").val() || $("#area").val();
		                //console.log(closeContent);
		             	// 在这里提交数据
		                var formdata = {"readId":readId,"verifyType":3,"id":GetQueryString("id"),"rejectReason":closeContent};
						$.ajax({
							type : 'post',
							url : urlRootPrefix + '/msgNoticeReads/read/verify',
							async : false,
							contentType: "application/json; charset=utf-8",  
							data : JSON.stringify(formdata),
							success : function(data) {
								if (!data.success) {
									layer.msg(data.msg, {
										shift : -1,
										time : 3000
									}, function() {
									});
									return;
								}
								layer.msg("审核通过成功", {
									shift : -1,
									time : 1000
								}, function() {
									window.location.href="javascript:history.go(-1)";
									layer.close(index);
								});
							}
						});
		            },
		            no:function (index,layero) {
		                 layer.close(index);
		            }
		        });
				
			});
			$("#verifyNo").click(function(){
				layer.open({
		            type: 1,
		            title:'请确认是否驳回该审核?',
		            area : [ '472px', '279px' ], //弹出层宽高
		            content: "<div style='margin-left:10px'>审核说明：</div><div style='display:flex;justify-content:center;'><textarea id='area' style='width:95%;height:150px;'></textarea></div>",
		            btn:['保存','取消'],
		            yes:function (index,layero) {
		                 //获取输入框里面的值
		                var closeContent = top.$("#area").val() || $("#area").val();
		                //console.log(closeContent);
		             	// 在这里提交数据
		                var formdata = {"readId":readId,"verifyType":4,"id":GetQueryString("id"),"rejectReason":closeContent};
						$.ajax({
							type : 'post',
							url : urlRootPrefix + '/msgNoticeReads/read/verify',
							async : false,
							contentType: "application/json; charset=utf-8",  
							data : JSON.stringify(formdata),
							success : function(data) {
								if (!data.success) {
									layer.msg(data.msg, {
										shift : -1,
										time : 3000
									}, function() {
									});
									return;
								}
								layer.msg("审核通过成功", {
									shift : -1,
									time : 1000
								}, function() {
									window.location.href="javascript:history.go(-1)";
									layer.close(index);
								});
							}
						});
		                
		                
		            },
		            no:function (index,layero) {
		                 layer.close(index);
		            }
		        });
			});
		});
		getIndustryPara();
		initData();
		
		function initData(){
			var id = GetQueryString("id");
			if(id){
				$.ajax({
					type : 'get',
					url : urlRootPrefix + '/customers/'+id,
					async : false,
					success : function(data) {
						var data = data.data;
						$('#customerId').val(data.customerId);
						$('#companyName').val(data.companyName);
						$('#companyAddr').val(data.companyAddr);
						$('#legalRepresentative').val(data.legalRepresentative);
						$('#registeredCapital').val(data.registeredCapital);
						$('#businessTermBegin').val(data.businessTermBegin);
						$('#businessTermEnd').val(data.businessTermEnd);
						$('#creditCode').val(data.creditCode);
						$('#businessUser').val(data.businessUser);
						$('#businessUserTel').val(data.businessUserTel);
						$('#createUserId').val(data.createUserId);
						$('#createTime').val(data.createTime);
						$('#registerPlace').val(data.registerPlace);
						$('#industryParaId').val(data.industryParaId);
						$('#followUserId').val(data.followUserName);
						$('#followUserId').attr("followUserId",data.followUserId);
					}
				});
			}
		}

		function update() {
			$('#form').bootstrapValidator();
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();
		    formdata.status = 2;
		    formdata.followUserId = $("#followUserId").attr("followUserId");
			$.ajax({
				type : 'put',
				url : urlRootPrefix + '/customers',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					if(!data.success){
						layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
						$("button[type='submit']").removeAttr("disabled");
						return;
					}
					layer.msg("修改成功", {shift: -1, time: 1000}, function(){
                        location.href = "customerList.html";
                    });
				}
			});
		}
		function getIndustryPara(){
		   	$.ajax({
		           type : 'get',
		           url : urlRootPrefix + '/paraValue/v2/listByParaTypeCode?paraTypeCode=industry',
		           async:false,
		           success : function(data) {
			           	if(!data.success){
			           		layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
							return;
						}
			           	var data = data.data;
			           	var typeHtml = "";
			           	for(var i=0;i<data.length;i++){
			           		typeHtml += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
			           	}
			           	$("#industryParaId").append(typeHtml);
		           }
		       });
		}
		function openIframeUserList(f) {
			var dt = {'ids':$(f).attr("followUserId"),'names':$(f).val()};
			layer.open({
				type : 2,
				title : "选择归属业务员",
				shadeClose : false,
				shade : 0.8,
				maxmin : false, //开启最大化最小化按钮
				area : [ '800px', '650px' ],
				content : urlRootPrefix + "/pages/common/userList.html",
				success: function ( layero,index) {
		        	//找到它的子窗口的body
		            var body = layer.getChildFrame('body', index), iframeWin = window[layero.find('iframe')[0]['name']];  
		          	//为子窗口元素赋值
		            body.contents().find("#ids").val(dt.ids);
		            body.contents().find("#names").val(dt.names);
		            //调用子窗口的事件
		            iframeWin.initData();
		            iframeWin.initOrgData();
		        },
				btn : [ '确定', '取消' ],
				yes : function(index, layero) {
					//按钮【按钮一】的回调
					var body = layer.getChildFrame('body', index);
					$("#followUserId").attr("followUserId",body.contents().find("#ids").val());
					$("#followUserId").val(body.contents().find("#names").val());
					layer.close(index);
				}
			});
		}
	</script>
</body>
</html>
